package com.ww.demo.thread;

public class ProduceTest1 {
	
	private static int MAX_PRODUCT = 10;
	private static int MIN_PRODUCT = 2;
	
	private int product = 0;
	
	public synchronized void produce(){
		if(this.product >= MAX_PRODUCT){
			try {
				wait();
				System.out.println("");
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
			return;
		}
		this.product++;
		System.out.println("生产者生产第:" + this.product + "产品");
		notifyAll();
	}
	
	
	public synchronized void consume(){
		if(this.product < MIN_PRODUCT){
			try {
				wait();
				System.out.println("缺货，请稍微");
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
			return;
		}
		System.out.println("消费者取走了" + this.product + "个产品");
		this.product--;
		notifyAll();
	}
	
	
	public static void main(String[] args) {
		
	}
	
	
	
}
